﻿<UserControl x:Class="VkClientIM.UI.ContactListPresenter"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
			 xmlns:localUI="clr-namespace:VkClientIM.UI"
			 xmlns:logic="clr-namespace:VkClientIM.Logic"
			 xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"

			 xmlns:converters="clr-namespace:VkClientIM.Converters" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" Name="Root" >
	<UserControl.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="..\Resources\ListView.xaml"/>
			</ResourceDictionary.MergedDictionaries>
			<converters:ByteArrayToImageConverter x:Key="ArrayToImageConverter"/>
			<converters:UrlToImageConverter x:Key="UrlToImageConverter"/>
			<CollectionViewSource Source="{Binding}" x:Key="viewSourceKey">
				<CollectionViewSource.SortDescriptions>
					<scm:SortDescription Direction="Ascending"/>
				</CollectionViewSource.SortDescriptions>
			</CollectionViewSource>
		</ResourceDictionary>
		
	</UserControl.Resources>
    <Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>
		<localUI:SearchTextBox Grid.Row="0" LabelText="Поиск" Search="SearchTextBoxSearch">
			<localUI:SearchTextBox.ToolTip>
				<StackPanel>
					<TextBlock Text="Быстрый поиск по контакт-листу"/>
					<TextBlock Text="Ищет по фамилии/нику/имени/статусу"/>
					<TextBlock Text="Кстати делает это даже в неправильной раскладке"/>
				</StackPanel>
			</localUI:SearchTextBox.ToolTip>
		</localUI:SearchTextBox>
		<ListView Name="list" Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ItemsSource="{Binding Source={StaticResource viewSourceKey}}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
			<ListView.ContextMenu>
				<ContextMenu Name="contextMenu">
					<MenuItem Header="Профиль" PreviewMouseUp="MenuItemProfileShow"/>
					<MenuItem Header="Послать личное сообщение" PreviewMouseUp="MenuItemSendStandAloneMessage"/>
					<MenuItem Header="Начать беседу" PreviewMouseUp="MenuItem_PreviewMouseUp"/>
					<MenuItem Header="Написать на стене"/>
					<MenuItem Header="Просмотреть стену"/>
				</ContextMenu>
			</ListView.ContextMenu>
			<ListView.ItemTemplate>
				<DataTemplate>
					<StackPanel Orientation="Horizontal">
						<StackPanel.ToolTip>
							<Border>
							<DockPanel Margin="2,2,2,2" MaxWidth="400">
									<Image Source="{Binding Path=Photo,Converter={StaticResource ArrayToImageConverter}}" MaxWidth="50"/>
								<StackPanel>
										<TextBlock Text="Фамилия:  "/>
										<TextBlock Text="Имя:"/>
										<TextBlock Text="Статус:"/>
								</StackPanel>
								<StackPanel>
									<TextBlock Text="{Binding Path=LastName}"/>
									<TextBlock Text="{Binding Path=FirstName}"/>
									<TextBlock Text="{Binding Path=Activity}" TextWrapping="Wrap"/>
								</StackPanel>
								</DockPanel>
							</Border>
						</StackPanel.ToolTip>
						<Border Width="60" Height="60" CornerRadius="5" Name="photoBorder">
							<Border Margin="5,5,5,5" CornerRadius="3">
								<Border.Background>
									<ImageBrush ImageSource="{Binding Path=Photo,Converter={StaticResource ArrayToImageConverter}}"/>
								</Border.Background>
							</Border>
						</Border>
						<StackPanel>
							<StackPanel Orientation="Horizontal">
							<TextBlock Text="{Binding Path=FirstName}"/>
							<TextBlock Text=" "/>
							<TextBlock Text="{Binding Path=NickName}"/>
							<TextBlock Text=" "/>
							<TextBlock Text="{Binding Path=LastName}"/>
							</StackPanel>
							<TextBlock Text="{Binding Path=Domain}"/>
							<TextBlock Text="{Binding Path=Activity}" />
						</StackPanel>
					</StackPanel>
					<DataTemplate.Triggers>
						<DataTrigger Binding="{Binding Path=Online}" Value="0">
							<Setter TargetName="photoBorder" Property="Background">
								<Setter.Value>
									<LinearGradientBrush>
										<GradientStop Color="Black" Offset="0"/>
										<GradientStop Color="Red" Offset="0.5"/>
										<GradientStop Color="Black" Offset="1"/>
									</LinearGradientBrush>
								</Setter.Value>
							</Setter>
						</DataTrigger>
						<DataTrigger Binding="{Binding Path=Online}" Value="1">
							<Setter TargetName="photoBorder" Property="Background">
								<Setter.Value>
									<LinearGradientBrush>
										<GradientStop Color="Black" Offset="0"/>
										<GradientStop Color="Green" Offset="0.5"/>
										<GradientStop Color="Black" Offset="1"/>
									</LinearGradientBrush>
								</Setter.Value>
							</Setter>
						</DataTrigger>
					</DataTemplate.Triggers>
				</DataTemplate>
			</ListView.ItemTemplate>
			<ListView.ItemContainerStyle>
				<Style BasedOn="{StaticResource MyListViewItem}" TargetType="{x:Type ListViewItem}">
					<EventSetter Event="PreviewMouseUp" Handler="ListItemPreviewMouse"/>
					<EventSetter Event="PreviewMouseDown" Handler="ListItemPreviewMouse"/>
				</Style>
			</ListView.ItemContainerStyle>
		</ListView>

	</Grid>
</UserControl>
